<template>
  <div>
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          fixed
          prop="id"
          label="仓库id"
          width="150">
      </el-table-column>
      <el-table-column
          prop="sname"
          label="仓库名称"
          width="200">
      </el-table-column>
      <el-table-column
          prop="cname"
          label="作物名称"
          width="180">
      </el-table-column>
      <el-table-column
          prop="zname"
          label="规格"
          width="180">
      </el-table-column>
      <el-table-column
          prop="total"
          label="总数量"
          width="150">
      </el-table-column>
      <el-table-column
          fixed="right"
          label="操作"
          width="300">
        <template slot-scope="scope">
          <el-button size="small" type="text" @click="openRow(scope.row)">
            <span style="color: #43e8ec;font-size: 20px">
            <i class="el-icon-s-promotion"></i>
            </span>
          </el-button>
          <el-button size="small" type="text" @click="show(scope.row)">
            <span style="color: #00ccbd;font-size: 20px">
            <i class="el-icon-menu"></i>
            </span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @current-change="gopage"
        :page-size="10"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>

    <el-dialog title="入库" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="生产厂商" :label-width="formLabelWidth">
          <el-select v-model="form.marketId" placeholder="请选择生产厂商">
            <el-option v-for="m in markets" :label="m.name" :value="m.id" v-bind:key="m.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数量" :label-width="formLabelWidth">
          <el-input v-model="form.num"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="outRow">确 定</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
export default {
  name: "RawView",
  data() {
    return {
      //2属性定义
      tableData:[],
      pageNum:1,
      total:0,
      form:{},
      formLabelWidth:"120px",
      dialogFormVisible:false,
      markets:[]
    }
  }, methods: {
    getMarketsList(){
      this.axios.post("cropservice/market/list").then(res=>{
        this.markets=res.data.data
      })
    },
    openRow(row){
      this.form=row
      this.dialogFormVisible=true
      this.getMarketsList()

    },
    outRow(){
      this.axios.post("cropservice/stash/outStash",this.form).then(res=>{
        if(res.data.code==200){
          this.$message.success(res.data.msg)
          this.del()
          this.dialogFormVisible=false

          this.getList()
        }else{
          this.$message.error(res.data.msg)
        }
      })
    },
    gopage(page){
      this.pageNum=page;
      this.getList();
    },
    getList(){
      this.axios.post("cropservice/scrop/list?pageNum="+this.pageNum).then(res=>{
        this.tableData=res.data.data.list;
        this.total=res.data.data.total;
      })
    },
    del(){
      this.axios.post("cropservice/stash/del",this.form).then(res=>{
       console.log(res)
      })
    }
  }, created() {
    //4.钩子函数
    this.getList();

  }
}
</script>

<style scoped>

</style>
